####Heat MAP
library(ALL) ##available from http://bioconductor.org/packages/data/experiment/1.7/src/contrib/html/ALL.html

data(ALL)
selSamples <- ALL$mol.biol %in% c("ALL1/AF4", "E2A/PBX1")
ALLs <- ALL[, selSamples]
ALLs$mol.biol <- factor(ALLs$mol.biol)
colnames(exprs(ALLs)) <- paste(ALLs$mol.biol, colnames(exprs(ALLs)))


library("genefilter")
meanThr <- log2(100)
g <- ALLs$mol.biol
s1 <- rowMeans(exprs(ALLs)[, g==levels(g)[1]]) > meanThr
s2 <- rowMeans(exprs(ALLs)[, g==levels(g)[2]]) > meanThr
s3 <- rowttests(ALLs, g)$p.value < 0.0002
selProbes <- (s1 | s2) & s3
ALLhm <- ALLs[selProbes,]

hmcol <- colorRampPalette(brewer.pal(10, "RdBu"))(256)
spcol <- ifelse(ALLhm$mol.biol=="ALL1/AF4", "goldenrod", "skyblue")
heatmap(exprs(ALLhm), col=hmcol, ColSideColors=spcol)

#######################################################
library(MLInterfaces)
B <- 50
N <- sum(selSamples)
M <- floor(N*2/3)
errors <- 0
for(i in 1:B){
  train <- sample(N,M)
  s3 <- rowttests(ALLs[,train], g[train])$p.value < 0.0002
  krun=knnB(ALLs[s3,],"mol.biol",trainInd=train)
  tmp<-confuMat(krun)
  print(tmp)
  errors <- sum(tmp)-sum(diag(tmp))
}
